package com.aijk.web.admin.controller.sys;

import com.aijk.commons.web.constant.DubboVersionSystemConstant;

import com.aijk.ehm.sys.api.LogApi;
import com.aijk.ehm.sys.model.SysLog;
import com.aijk.ehm.sys.model.qo.LogQo;
import com.aijk.web.admin.RetMsg;
import com.aijk.web.admin.controller.BaseController;
import com.aijk.web.admin.utils.DataTableUtil;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;

@Controller
@RequestMapping(value = "/admin/sys/log")
public class LogController extends BaseController {

	protected Logger logger = LoggerFactory.getLogger(this.getClass());

	@Reference(version = DubboVersionSystemConstant.DUBBO_VERSION_SYS_LOG_API)
	private LogApi logApi;

	@RequestMapping(value = "/list", method = RequestMethod.GET)
	@RequiresPermissions("admin:sys:log:list")
	public String list_view() {
		return "sys/log_list";
	}

	@RequestMapping(value = "/list", method = RequestMethod.POST)
	@RequiresPermissions("admin:sys:log:list")
	 public @ResponseBody
	RetMsg list(@RequestParam HashMap skey, @RequestParam(value = "draw", defaultValue = "1") Integer draw) {
		Long iTotalRecords;
		DataTableUtil.FormatOptions(skey);
		LogQo qo = DataTableUtil.fillQo(skey,LogQo.class);
		draw += 1;
		PageInfo<SysLog> logList = logApi.getPage(qo);

		iTotalRecords =logList.getTotal();
		RetMsg regMsg = new RetMsg();

		regMsg.put("data",   logList.getList());
		regMsg.put("draw", draw);
		regMsg.put("recordsTotal", iTotalRecords);
		regMsg.put("recordsFiltered", iTotalRecords);

		return regMsg;
	}

}
